﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YS.Domain.IoT.Receive;

namespace YS.Domain.IoT.Logging.Dto
{
    public class CommandContext
    {
        public CommandContext(RequestInfo request)
        {
            this.CreatedTime = DateTime.Now;
            this.BeginTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
            this.EventId = request.EventId;
            this.Version = request.Version;
            this.Key = request.Key;
            this.Body = request.Body;
            this.Sign = request.Sign;
            this.Message = request.MessageId;
            this.ClientId = request.ClientId;
            this.PublishTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
            this.ConsumedTimes = 1;
            this.Channel = 100;
            this.CreatedTime = DateTime.Now;
            this.Mid = request.Mid;
        }
        public string EventId { get; private set; }
        public object? Payload { get; set; }
        public DateTime CreatedTime { get; private set; }

        /// <summary>
        /// 取消任务 Token
        /// </summary>
        /// <remarks>用于取消本次消息处理</remarks>
        public CancellationToken CancellationToken { get; }

        /// <summary>
        /// Gets version.
        /// </summary>
        public string Version { get; private set; }

        /// <summary>
        /// Gets the  command Key.
        /// </summary>
        public string Key { get; private set; }

        /// <summary>
        /// Gets the  command Body.
        /// </summary>
        public string Body { get; private set; }

        /// <summary>
        /// Gets the  command Sign.
        /// </summary>
        public string Sign { get; private set; }

        /// <summary>
        /// 消息体Id
        /// </summary>
        public string Message { get; private set; }

        /// <summary>
        /// 编号 mqtt or sessionId
        /// </summary>
        public string ClientId { get; private set; }

        /// <summary>
        /// 消息发布时间
        /// </summary>
        public long PublishTime { get; set; }

        /// <summary>
        /// 执行次数
        /// </summary>
        public short ConsumedTimes { get; set; }

        /// <summary>
        /// mqtt实例
        /// </summary>
        public string InstanceId { get; private set; }

        /// <summary>
        /// topic
        /// </summary>
        public string Topic { get; private set; }

        /// <summary>
        /// topic2
        /// </summary>
        public string SecondTopic { get; set; }

        /// <summary>
        /// 处理服务名称
        /// </summary>
        public string HostName { get; private set; }

        /// <summary>
        /// 消息标识符
        /// </summary>
        public string Id { get; private set; }

        /// <summary>
        /// 来源 0~99,mqtt, 100 socket
        /// </summary>
        public short Channel { get; private set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public long BeginTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public long EndTime { get; set; }

        public string Exception { get; set; }
        public string Mid { get; private set; }
        public string ResponseId { get; set; }
        public string ResponseBody { get; set; }
    }
}
